package gameManager;

import java.awt.Point;
import java.util.List;

/**
 * This class manages the weapons that a player can use. Any new weapons
 * will be subclasses of this class.
 * @author Stephen Hunt and Kannan Raju
 *
 */
public abstract class WeaponObject {

    private Point myPosition;
    private int cooldownTime;
    private int myWeaponLevel;
    private String myWeaponName;
    private int timeUntilNextFire;
    private int triggerTimeFromLastFired;
    private AmmunitionObject myAmmunition;
    private GameCharacter myParent;
    
    /**
     * The Constructor for the class, taking in parameters governing the
     * power of the weapon and managing it. 
     * @param weaponLevel The level of the weapon (how powerful it is, e.g.multiple bullets)
     * @param cooldownTime The time between fire.
     * @param parent The character which owns the weapon (the player/enemies)
     */
    public WeaponObject (int weaponLevel, int cooldownTime,
                         GameCharacter parent) {
        setWeaponLevel(weaponLevel);
        setCooldownTime(cooldownTime);
        triggerTimeFromLastFired = 0;
        myParent = parent;
    }
    /**
     * Sets the name of the Weapon.
     * @param newWeaponName The new name of a weapon
     */
    public void setWeaponName (String newWeaponName) {
        myWeaponName = newWeaponName;
    }
    /**
     * Gets the weapon name.
     * @return
     */
    public String getWeaponName() {
        return myWeaponName;
    }
    /**
     * Retrieves the level of the weapon.
     * @return
     */
    public int getWeaponLevel() {
        return myWeaponLevel;
    }
    /**
     * Sets the Level of the Weapon.
     * @param newWeaponLevel The new level of the weapon to be
     * set.
     */
    public void setWeaponLevel(int newWeaponLevel) {
        myWeaponLevel = newWeaponLevel;
    }
    /**
     * Changes the weapon level by some amount, typically incrementing
     * by dWeaponLevel.
     * @param dWeaponLevel The weapon level differential.
     */
    public void changeWeaponLevel (int dWeaponLevel) {
        myWeaponLevel += dWeaponLevel;
    }
    /**
     * Retrieves the cooldown time for the weapon.
     * @return
     */
    public int getCooldownTime() {
        return cooldownTime;
    }
    /**
     * Establishes the cooldwon time, in seconds, for the weapon.
     * @param newCoolDownTime The new firing rate for the weapon.
     */
    public void setCooldownTime(int newCoolDownTime) {
        cooldownTime = newCoolDownTime;
    }
    /**
     * Changes the exisiting cooldowntime for a weapon.
     * @param dCoolDownTime The amount of time to be added/
     * subtracted from the previous time.
     */
    public void changeCoolDownTime(int dCoolDownTime) {
        cooldownTime += dCoolDownTime;
    }
    /**
     * Keeps track of and manges the cooldwon time through the use of the
     * time trigger, allows the player from firing based on timeuntilnext
     * fire.
     * @param trigger the current time
     */
    public void updateCoolDownWaitingTime(int trigger) {

        timeUntilNextFire = cooldownTime + triggerTimeFromLastFired - trigger;
        if (timeUntilNextFire < 0) {
            timeUntilNextFire = 0;
        }
        triggerTimeFromLastFired = trigger;
    }
    /**
     * Retrieves the Ammunition that this particular weapon
     * is using.
     * @return
     */
    public AmmunitionObject getWeaponAmmunition() {
        return myAmmunition;
    }
    /**
     * Establishes the ammo a certain weapon will use.
     * @param newAmmo
     */
    public void setWeaponAmmunition(AmmunitionObject newAmmo) {
        myAmmunition = newAmmo;
    }
    /**
     * Fires the specified ammo.
     * @return
     */
    public abstract List<AmmunitionObject> fire();
    /**
     * Returns a boolean based on whether the cooldown is
     * not in effect, when the player is allowed to fire.
     * @return
     */
    public boolean okayToFire(){
        return (timeUntilNextFire <= 0);
    }
    /**
     * Retrieves the current position of the object which the
     * weapon belongs to.
     * @return
     */
    public Point getPosition(){
        return myPosition;
    }
    /**
     * Establishes the position of the weapon when it is firing.
     * @param newPosition
     */
    public void setPosition(Point newPosition){
        myPosition = newPosition;
    }
    /**
     * Retrieves the object to which the weapon belongs to.
     * @return
     */
    public GameCharacter getParent(){
        return myParent;
    }
}

